const express = require('express')
const app = express();
// 引入mysql的依赖模块
const mysql = require('mysql');
// 创建mysql的链接池
const db = mysql.createPool({
    host: 'localhost',
    port: 3306,
    user: 'root',
    password: '123456',
    database: 'shopdb'
})
app.get('/list', (req, res) => {
   // 新增
    //  let sql = "insert into t_goods values (5,'【8+256】苹果15promax','手机','./images/01.png',3299)"
    // 删除
    // let sql = "delete from t_goods where id = 1"
    // 更改
    // let sql = "update t_goods set price = price * 2 where id = 4"
    // 查询
    let sql = 'select * from t_goods'

    // 调用query方法访问数据库，[]为请求的参数，result是数据库的响应数据
    db.query(sql, [], (err, result) => {
        res.send(result)
    })
})
app.listen(3001, () => {
    console.log("sever is running at port 3001!");
})